var details = null;

var loadData = function(){
	details= JSON.parse(getCookie("rmd_details"));
}



var buildParams =function(){
    var params ={"token":getParamValue("token"),"staffNo":getEmpCode(),"passUrl":"rmdId="+details.rmdId+"&rmdCategory="+details.rmdCategory};
    return params;
};

var handleReminder =function(){
	  	var params = buildParams();
	 	$.ajax({
		    type: "post",
		    contentType: "application/json",
		    data: JSON.stringify(params),
		    url: Constants.rpcEsopHost+"readRemind",
		    dataType: "json",
		    async: true,
		    headers: {
      'token': getParamValue('token'),
      'saleType': getParamValue('saleType')
    },
    success: function(data) {
      if (data.ResultCode === 1009) {
        alert('登陆超时，请重新登录！');
        jumpToSignin();
        return;
      }
		    	console.log("data = "+data);
		        console.info(data);
		        if(data.rtnCode!=1000){
		        	alert("处理失败："+data.rtnMsg);
		        	console.log("RPC处理提醒接口返回失败！code:"+data.rtnCode);
		        	return;
		        }
		        if(data.return.resultCode!="00"){
		        	alert("处理失败："+data.return.resultDesc);
		        	console.log("处理提醒接口返回失败！code:"+data.return.resultCode);
		        	return;
		        }
		        //成功，则返回列表页面，并刷新
		        window.history.back(-1);
		    },
		    error : function(textStatus) {
		    	alert("处理失败！服务器没有返回。");
		        console.info("request error:");
		    }
		  });
};


var deleteReminder =function(){
  	params = buildParams();
 	$.ajax({
	    type: "post",
	    contentType: "application/json",
	    data: JSON.stringify(params),
	    url: Constants.rpcEsopHost+"deleteRemind",
	    dataType: "json",
	    async: true,
	    headers: {
      'token': getParamValue('token'),
      'saleType': getParamValue('saleType')
    },
    success: function(data) {
      if (data.ResultCode === 1009) {
        alert('登陆超时，请重新登录！');
        jumpToSignin();
        return;
      }
	    	console.log("data = "+data);
	        console.info(data);
	        if(data.rtnCode!=1000){
	        	alert("处理失败："+data.rtnMsg);
	        	console.log("RPC删除提醒接口返回失败！code:"+data.rtnCode);
	        	return;
	        }
	        if(data.return.resultCode!="00"){
	        	alert("处理失败："+data.return.resultDesc);
	        	console.log("删除提醒接口返回失败！code:"+data.return.resultCode);
	        	return;
	        }
	        //成功，则返回列表页面，并刷新
	        window.history.back(-1);
	    },
	    error : function(textStatus) {
	    	alert("删除失败！服务器没有返回。");
	        console.info("request error:");
	    }
	  });
};


var hideForward =function(){
	   if(!$("#forward").hasClass("am-hide")){
		   $("#forward").addClass("am-hide");
	   }
};
var showForward =function(){
	   if($("#forward").hasClass("am-hide")){
		   $("#forward").removeClass("am-hide");
	   }    
};
var hideHandle =function(){
	   if(!$("#handle").hasClass("am-hide")){
		   $("#handle").addClass("am-hide");
	   } 
};

var showHandle =function(){
	   if($("#handle").hasClass("am-hide")){
		   $("#handle").removeClass("am-hide");
	   } 	
};

var hideDelete =function(){
	   if(!$("#delete").hasClass("am-hide")){
		   $("#delete").addClass("am-hide");
	   } 
};

var showDelete =function(){
	   if($("#delete").hasClass("am-hide")){
		   $("#delete").removeClass("am-hide");
	   } 
};

$(function(){
   loadData();
   //alert(details);
   console.info(details);
   $("#title").html(rmdType2Name(details.rmdType));
   $("#content").html(details.rmdContent);
   $("#rmdDay").html(details.rmdDay);
   
   //只读，则全部都隐藏
   if(getParamValue("readOnly")==1){
	   hideForward();
	   hideDelete();
	   hideHandle();
   }else{
	   //已读，仅显示删除
	   if(details.rmdReadState==1){
		   hideForward();
		   hideHandle();
	   }else{
	   //未读，则全部都显示
		   showForward();
		   showHandle(); 
	   }
	   
	   showDelete();
	   
   }
  
   

   
   $("#forward").on("click",function(){
       //window.location.href = "reminder_add.html" + "?" + getParams();
	   alert("敬请期待");
     });
   
   $("#delete").on("click",function(){
	   $("#modal_msg").html("是否删除本条提醒");
	   $('#myConfirm').modal({
	          relatedTarget: this,
	          onConfirm: function(options) {
	        	  deleteReminder();
	          },
	          // closeOnConfirm: false,
	          onCancel: function() {
	            //alert('算求，不弄了');
	          }
	        });
     });

   
   $("#handle").on("click",function(){
	     $("#modal_msg").html("是否处理本条提醒");
         $('#myConfirm').modal({
          relatedTarget: this,
          onConfirm: function(options) {
        	  handleReminder();
          },
          // closeOnConfirm: false,
          onCancel: function() {
            //alert('算求，不弄了');
          }
        });
     });
	
});